/*
 *  CatSpawnSet.cpp
 *  
 *
 *  Created by Guo Wei Tan on 1/17/14.
 *  Copyright 2014 Catropico. All rights reserved.
 *
 */

#include "CatSpawnSet.h"

using namespace cocos2d;

//===== CONSTRUCTOR =====
CatSpawnSet::CatSpawnSet(int typeOfCat, float spawnInterval, float numberToSpawn, float prespawnDelay)
{
	_typeOfCat = typeOfCat;
	_spawnInterval = spawnInterval;
	_spawnTimer = 0;
	_prespawnDelay = prespawnDelay;
	_numberToSpawn = numberToSpawn;
}

//===== FUNCTIONS =====

/*!
    @function CatSpawnSet
    @param		timeLapse:float
				time lapsed since the previous call to this function
    @result		returns true if this Cat set is ready to spawn, else returns false.
				This function reduces/resets the spawn timer and spawn counter automatically based on time lapse.
 */

bool CatSpawnSet::reduceSpawnTimer(float timeLapse)
{
	//no more cats to spawn
	if (_numberToSpawn <= 0)
		return false;
	
	_spawnTimer -= timeLapse;
	
	//not time to spawn yet
	if (_spawnTimer > 0)
		return false;

	//excess time lapsed overflow to new interval
	_spawnTimer = _spawnInterval + _spawnTimer; //reset the spawn interval timer
	_numberToSpawn--;
	return true;
}

bool CatSpawnSet::hasFinishedSpawning()
{
	return _numberToSpawn <= 0;
}
